/**
 * 
 * Sun CMS
 * 
 * @author			Burning
 * @copyright		Copyright (c) 2009, IsunCms.Com.
 * @license			http://www.isuncms.com/license.htm
 * @link				http://www.isuncms.com/
 * @since				Version 1.0 Beta
 * 
 */

function select_af(str){
	if(str[1]==1){
		$("#"+str[0]+'list').show();
	}else if(str[1]==0){
		$("#"+str[0]+'list').hide();
	}
}



//设置全局变量
var arColumn = 0;

//添加/修改文章
function addUptArticle(str){
	var insertId = $("#ar_id").val();
	var flag = $("#flag").val();
	if(str=='update'){
		if(insertId==0&&flag=='add'){
			alert('错误的操作，您还未提交过任何文章！');
			return false;
		}else{
			var oldThumbPic = $("#old_small_pic").val();
		}
	}else{
		if(flag==1){
			alert('文章已经提交过了，请不要重复提交！');
			return false;
		}
	}
	if( check_column() == false || check_title() == false ) return false;
	var content=KE.util.getData('content');
	if(content==''){
		$("#check_content").html('<img height="16" width="16" border="0" src="images/admin/publish_x.png"/>内容不能为空！');
		return false;
	}else{
		$("#check_content").html('');
	}
	if(str!='add'){
		$("#sys_msg").text('系统提示：文章保存中，如果您选择了下载远程图片，系统处理时间可能会稍长，请等待！');
		$("#msg_box").show(800);
	}
	var column_id=$("#column_id").val();
	var title=$("#title").val();
	var small_title=$("#small_title").val();
	var tags=$("#tags").val();
	var keywords=$("#keywords").val();
	var author=$("#author").val();
	var from=$("#from").val();
	var index_top=$("#index_top").attr('checked')==true?1:0;
	var column_top=$("#column_top").attr('checked')==true?1:0;
	var recommend=$("#recommend").attr('checked')==true?1:0;
	var title_color=$("#title_color").val();
	var special_id=$("#special_id").val();
	var description=$("#description").val();
	var url_jump=$("#url_jump").val();
	var comment=$("#comment").attr('checked')?1:0;
	var money=$("#money").val();
	var add_time=$("#add_time").val();
	var validate=$("#validate").attr('checked')==true?1:0;
	var password=$("#password").val();
	var thumb_pic=$("#thumb_pic").val();
	var draft=$("#draft").attr('checked')==true?1:0;
	var down_pic=$("#down_pic").attr('checked')==true?1:0;
	var get_first_pic=$("#get_first_pic").attr('checked')==true?1:0;
	var contentData;
	if(str=='update'){
		contentData={'ar_basic':{'column_id':column_id,'title':title,'small_title':small_title,'thumb_pic':thumb_pic,'tags':tags,'keywords':keywords,'author':author,'index_top':index_top,'from':from,'column_top':column_top,'recommend':recommend,'title_color':title_color,'special_id':special_id,'description':description,'url_jump':url_jump,'comment':comment,'money':money,'add_time':add_time,'validate':validate,'password':password,'draft':draft},'ar_content':{'old_thumb_pic':oldThumbPic,'down_pic':down_pic,'get_first_pic':get_first_pic,'content':content}};
	}else{
		contentData={'ar_basic':{'column_id':column_id,'title':title,'small_title':small_title,'thumb_pic':thumb_pic,'tags':tags,'keywords':keywords,'author':author,'index_top':index_top,'from':from,'column_top':column_top,'recommend':recommend,'title_color':title_color,'special_id':special_id,'description':description,'url_jump':url_jump,'comment':comment,'money':money,'add_time':add_time,'validate':validate,'password':password,'draft':draft},'ar_content':{'down_pic':down_pic,'get_first_pic':get_first_pic,'content':content}};
	}
	var postUrl;
	if( str=='update' ){
		if(flag=='0'||flag=='add'){
			postUrl = 'admincp.php?m=article&a=updatear&id='+insertId+'&page=0';
		}else{
			postUrl = 'admincp.php?m=article&a=updatear&id='+insertId+'&page=1';
		}
	}else{
		postUrl = 'admincp.php?m=article&a=addarticle';
	}
	$.ajax({
		type: "POST",
		url: postUrl,
		data: {'data':JSON.stringify(contentData)},
		dataType:'json',
		success: function(rs){
			if(rs.ok==1){
				if(str=='add'){
					window.location='admincp.php?m=article&a=index';
				}else if(str=='apply'){
					$("#ar_id").val(rs.aid);
					$("#flag").val(1);
					$("#sys_msg").text('系统提示：文章保存成功！');
				}else if(str=='update'){
					$("#sys_msg").text('系统提示：文章修改成功！');
				}
				arColumn=column_id;
				$("#old_thumb_pic").val(thumb_pic);
				$("#tags").val(rs.tags);
				$("#keywords").val(rs.keywords);
				$("#description").val(rs.description);
				$("#msg_box").show(1000);
				setTimeout("$('#msg_box').hide(1000)",6000);
			}else{
				alert('文章保存失败，请联系管理员！');
				return false;
			}
		}
	});
}

function empty_form(){
	addflag = 0;
	arColumn = 0;
	$("#ar_id").val(0);
	$("#title").val('');
	clearEditor('content');
	$("#small_title").val('');
	$("#tags").val('');
	$("#keywords").val('');
	$("#author").val('');
	$("#from").val('');
	$("#index_top").removeAttr('checked');
	$("#column_top").removeAttr('checked');
	$("#recommend").removeAttr('checked');
	$("#title_color").val('');
	$("#special_id").val('');
	$("#description").val('');
	$("#url_jump").val('');
	if($("#comment").attr('checked')==false){
		$("#comment2").removeAttr('checked');
		$("#comment").attr('checked','true');
	}
	$("#money").val('');
	$("#validate").attr('checked','true');
	$("#password").val('');
	$("#small_pic").val('');
	$("#draft").removeAttr('checked');
	$("#down_pic").removeAttr('checked');
	$("#get_first_pic").removeAttr('checked');
	var time=mydata();
	$("#add_time").val(time);
}